<?php

namespace Product\Model;

use Zend\Db\TableGateway\TableGateway;
use Product\Entity\Category;

class CategoryTable{
    
    protected $tableGateway;
    
    public function __construct(TableGateway $tableGateway) {
        $this->tableGateway = $tableGateway;
    }
    
    public function saveCategory(Category $category)
    {
	$data = array(
            'name' => $category->getName(),            
        );
        
        $id = (int)$category->getId();
        if($id == 0)
        {  
            $this->tableGateway->insert($data);
        }    
	return $this->tableGateway->getLastInsertValue();     
    }
}
